mui.init({
	subpages: [{
		url: 'friend_info.html', //子页面HTML地址，支持本地地址和网络地址
		id: 'friend_info.html', //子页面标志
		styles: {
			top: '44px', //子页面顶部位置
			bottom: '0px',
			bounce: 'vertical'
		}
	}]
});
mui.plusReady(function() {
	var friend_id = plus.storage.getItem('temp_friend_id'),
		user_id = plus.storage.getItem('cg_user_id'),
		user_token = plus.storage.getItem('cg_user_token'),
		remark = '';
	$('.btn-action').on('tap', function(e) {
		var _this = this,
			remark = $('.remark').val(),
			to_user_id = friend_id,
			remark = $('.remark').text(),
			add_flag = $(this).text() == '添加' ? true : false;
		if(add_flag) {
			mui.openWindow({
				url: 'send_check_info.html',
				extras: {
					'to_user_id': to_user_id,
					'remark': remark
				}
			});
		} else {
			mui.confirm('确定删除好友？','提示', function(value) {
				if(value.index == 1) {
					myAjax('addresslist/front_user_relation/deleteFriends', 'post', {
						'user_id': user_id,
						'user_token': user_token,
						'to_user_id': friend_id
					}, function(data) {
						if(data.success) {
							refresh_address_list();
							mui.alert(data.msg, '提示', function() {
								mui.back();
							});
						} else {
							mui.alert('删除失败', '提示');
						}
					});
				}
			});
		}
	});
	function refresh_address_list() {
		var list = plus.webview.getWebviewById('address_list.html');
		mui.fire(list, 'refresh');//触发列表界面的自定义事件（refresh）,从而进行数据刷新
		return true;//返回true，继续页面关闭逻辑
	}
});
window.onload = function(){
	window.addEventListener("pageflowrefresh", function(e) {
		if(e.detail.is_friend==1){
			$('.btn-action').text('删除').addClass('btn-delete')
		}else{
			$('.btn-action').text('添加').addClass('btn-add')
		}
		plus.nativeUI.closeWaiting();
		mui.currentWebview.show('slide-in-right',200);
	});			 
}